package com.ldy.transmit.interceptor;

import java.net.URI;

import com.ldy.transmit.common.util.ConfigUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;


public class LdyRequest implements HttpRequest{
	private HttpRequest httpRequest;

	LdyRequest(HttpRequest httpRequest){
		this.httpRequest = httpRequest;
	}
	
	@Override
	public HttpHeaders getHeaders() {
		return httpRequest.getHeaders();
	}

	@Override
	public HttpMethod getMethod() {
		return httpRequest.getMethod();
	}

	@Override
	public String getMethodValue() {
		return httpRequest.getMethodValue();
	}

	@Override
	public URI getURI() {
		URI uri = httpRequest.getURI();
		String uriStr = uri.toString();
		String configHost = ConfigUtil.get(uri.getHost());
		if ( configHost != null && !"".equals(configHost.trim())) {
			configHost = configHost.replaceFirst("^https?://", "");
			return uri.resolve(uriStr.replaceFirst(uri.getHost(), configHost));
		}
		return uri;
	}

}
